﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using SystemContainer.Models;


namespace SystemContainer.Controllers
{
    public class AreaOfInterestRecommendationController : Controller
    {
        private DAO dao = new DAO();
      //  Compute compute = new Compute();
         
        public List<City> ChooseLocation()
        {
            //   ViewBag.locationName= new SelectList(systemDB.Locations, "GenreId","Name");
            List<City> cityList = dao.getAllCities();
            return cityList;            
        }


        public ActionResult BrowseLocation(int cityID)
        {

            City city = dao.searchCityByCityID(cityID);
            CityJsonObject cityJson= new CityJsonObject{
                CityID=city.CityID,
                locationName=city.locationName,
                Latitude=city.Latitude,
                Longtitude=city.Longtitude,
                type=city.type
              
            };
          //  Console.WriteLine(city.CityID);
            return Json(cityJson);
        }

        public ActionResult ShowAllAreaOfInterest(int cityID)
        {
            List<AreaOfInterest> AOIList = dao.searchAOIbyCityID(cityID);
            int size = AOIList.Count;
            List<AreaOfInterestJsonObject> AOIJsonList = new List<AreaOfInterestJsonObject>();

            for (int i = 0; i < size; i++)
            {
                AOIJsonList.Add(new AreaOfInterestJsonObject
                {
                    AreaOfInterestID = AOIList[i].AreaOfInterestID,
                    CityID = AOIList[i].CityID,
                    rank = AOIList[i].rank,
                    RankAlgorithmID = AOIList[i].RankAlgorithmID,
                    type = AOIList[i].type,
                    locationName = AOIList[i].locationName,
                    Latitude = AOIList[i].Latitude,
                    Longtitude = AOIList[i].Longtitude
                });
            }
            return Json(AOIJsonList);
        }
            public ActionResult ShowAreaOfInterest(int cityID, double nelat, double nelng, double swlat, double swlng)
        {   List<AreaOfInterest> AOIList = dao.searchAOIbyBounds(cityID,nelat,nelng,swlat, swlng);
        int size = AOIList.Count;
            List<AreaOfInterestJsonObject> AOIJsonList=new List<AreaOfInterestJsonObject>();
            
            for (int i = 0; i < size; i++)
            {
                AOIJsonList.Add(new AreaOfInterestJsonObject
                {
                    AreaOfInterestID = AOIList[i].AreaOfInterestID,
                    CityID = AOIList[i].CityID,
                    rank = AOIList[i].rank,
                    RankAlgorithmID = AOIList[i].RankAlgorithmID,
                    type = AOIList[i].type,
                    locationName = AOIList[i].locationName,
                    Latitude = AOIList[i].Latitude,
                    Longtitude = AOIList[i].Longtitude
                });
            }
            return Json(AOIJsonList);


                
        }

            public ActionResult ShowAOIVenue(int AOIID, int cityID)
        {
           
            List<Venue> venueList = dao.searchVenueByAOIID(AOIID,cityID);
            List<VenueJsonObject> venueJsonList = new List<VenueJsonObject>();
           
            
            for (int i = 0; i < venueList.Capacity; i++)
            {
                venueJsonList.Add(new VenueJsonObject
                {
                    VenueID=venueList[i].VenueID,
                    AreaOfInterestID=venueList[i].AreaOfInterestID,
                    AOICityID = venueList[i].AOICityID,
                    type = venueList[i].type,
                    Latitude = venueList[i].Latitude,
                    locationName = venueList[i].locationName,
                    Longtitude = venueList[i].Longtitude

                });
            }
           


     

            return Json(venueJsonList);
           
        }
        public ActionResult ShowAOIScenicLocation(int AOIID,int cityID)
        {

            List<ScenicLocation> slList = dao.searchScenicLocationByAOIID(AOIID,cityID);
            List<ScenicLocationJsonObject> slJsonList = new List<ScenicLocationJsonObject>();


            for (int i = 0; i < slList.Capacity; i++)
            {
                slJsonList.Add(new ScenicLocationJsonObject
                {
                    ScenicLocationID = slList[i].ScenicLocationID,
                    AreaOfInterestID = slList[i].AreaOfInterestID,
                    AOICityID = slList[i].AOICityID,
               CityID=slList[i].CityID,
                    type = slList[i].type,
                    Latitude = slList[i].Latitude,
                    locationName = slList[i].locationName,
                    Longtitude = slList[i].Longtitude,
                    picUrl=slList[i].picUrl
                });
            }





            return Json(slJsonList);
           
        }
        [HttpPost]
        public ActionResult ShowLocationDetail(int locationID,int locationType)
        {   Location location= dao.searchLocationDetail(locationID,locationType);
        LocationJsonObject locationJson = new LocationJsonObject
        {
            locationName=location.locationName,
            Latitude=location.Latitude,
            Longtitude=location.Longtitude,
            type=location.type

        };
            return Json(locationJson);
        }

        public ActionResult ShowVenueDetail(int venueID)
        {
            Venue venue = dao.searchVenueDetail(venueID);
            VenueJsonObject venueJson = new VenueJsonObject
            {
                AreaOfInterestID= venue.AreaOfInterestID,
                VenueID=venue.VenueID,
                locationName = venue.locationName,
                Latitude = venue.Latitude,
                Longtitude = venue.Longtitude,
                type = venue.type
            };
            return Json(venueJson);
        }
        public ActionResult ShowScenicLocationDetail(int slID,int cityID)
        {
            ScenicLocation sl = dao.searchScenicLocationDetail(slID,cityID);
            ScenicLocationJsonObject ScenicLocationJson = new ScenicLocationJsonObject
            {
                AreaOfInterestID = sl.AreaOfInterestID,
                ScenicLocationID = sl.ScenicLocationID,
                locationName = sl.locationName,
                Latitude = sl.Latitude,
                Longtitude = sl.Longtitude,
                type = sl.type,
                picUrl=sl.picUrl
            };
            return Json(ScenicLocationJson);
        }
    }
}
